import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

// 进度条
let progress = (val, item) => {
	let total = Number(item.quantity) + Number(item.lq_num);
	let num = Number(item.lq_num) / total
	// console.log(num)
	return num.toFixed(2);
}
// 倒计时
let countDown = (val) => {
	let time = parseInt(new Date().getTime() / 1000)
	return val - time
}

// 浏览数
let browseNum = (val) => {
	let bnum = uni.$u.random(val, val*1000);
	let num;
	if(bnum > 9999){//大于9999显示x.xx万
	    num=(Math.floor(bnum/1000)/10) + 'W';
	}else{
		num = bnum
	}
	return num
}
// 快递类型
let expressType = (val) => {
	let text = ""
	switch (val) {
		case "CASH":
			text = "代金券";
			break;
		case "DISCOUNT":
			text = "折扣券";
			break;
		case "GIFT":
			text = "礼品券";
			break;
		default:
			text = "商品券";
			break;
	}
	return text;
}


// 券类型
let cardType = (val) => {
	let text = ""
	switch (val) {
		case "CASH":
			text = "代金券";
			break;
		case "DISCOUNT":
			text = "折扣券";
			break;
		case "GIFT":
			text = "礼品券";
			break;
		default:
			text = "商品券";
			break;
	}
	return text;
}


// 价格00
let cutPrice = (val) => {
	if(val){
		let arr =  Number(val).toFixed(2).split(".")
		if(arr[1] == "00"){
			return arr[0]
		}else{
			return val
		}
	}else{
		return "0"
	}
}


export {
	progress,
	cardType,
	cutPrice,
	countDown,
	browseNum,
	expressType
}
